<?php
	$movtypes	= array("mov","avi","mpg","mpeg","divx","ogm","mp4","mkv","m4v","mp4v");	// What are movie file extensions
	$moviefiles = array();

	$movdir = $argv[1];
	if(file_exists($movdir) and is_dir($movdir)){
		trackdir($movdir);
	}
	sort($moviefiles);
	echo implode("\n",$moviefiles);
	
	
	function trackdir($directory){
		global $movtypes, $moviefiles;

		if(substr($directory,-1,1) != "/"){ $directory .= "/"; }
		$mdir = opendir($directory);
		while(false !== ($file = readdir($mdir))){
			if(substr($file,0,1) == "."){ continue; }
			if(is_dir($directory.$file)){
				trackdir($directory.$file);
			}else{
				$ext = strtolower(substr($file, strrpos($file, ".")+1));
				if(in_array($ext, $movtypes)){							// It is a movie
					array_push($moviefiles, $directory.$file);
				}
			}
		}
	}

?>